<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/index.css">
    <link rel="stylesheet" href="css/register.css">
    <script src="js/cookie.js"></script>
</head>
<body>
<div class="wrap">
    <div class="mi" align="center">
        <img src="img/login1.png">
    </div>
    <h4>注册小米账号</h4>
    <div class="regbox">
        <h5 class="a2">国家/地区</h5>
        <input type="text" placeholder="中国">

        <h5 class="a1">成功注册帐号后，国家/地区将不能被修改</h5>
        <form>
            <p>
                <label>
                    <input name="uname" type="text" placeholder="请输入手机号码">
                </label>
            <h5 id="name_msg" class="a1" style="color: #f66">请输入手机号码</h5>
            </p>
            <p>
                <label>
                    <input name="upwd" type="password" placeholder="请输入密码">
                </label>
            <h5 id="pwd_msg" class="a1" style="color: #f66">请输入密码</h5>
            </p>
            <button>立即注册</button>
        </form>

    </div>
    <div class="msg">
        <p>
            <input type="checkbox">
            注册帐号即表示您同意并愿意遵守小米
            <span>用户协议</span>和
            <span>隐私政策</span>
        </p>
    </div>
</div>
<div class="footer">
    <div class="list">
        <ul>
            <li class="on">简体</li>
            <li>繁体</li>
            <li>English</li>
            <li>常见问题</li>
        </ul>
    </div>
    <p class="nf-intro">
        <span>小米公司版权所有-京ICP备10046444-
            <a><img src="img/ghs.png" alt=""></a>
            京公网安备11010802020134号-京ICP证110507号</span>
    </p>
</div>
</body>
</html>
<script>
    var oForm=document.forms[0];
    var o_name=document.getElementById("name_msg");
    var o_pwd=document.getElementById("pwd_msg");
    var unameFlag=false;
    var upwdFlag=false;
    oForm.uname.onblur=function () {
        unameFlag=/^[\d]{11}$/;
        if(unameFlag.test(this.value)){
            o_name.innerHTML="手机号正确".fontcolor("green")
        }else{
            o_name.innerHTML="手机号码格式错误";
        }
    }
    oForm.upwd.onblur=function () {
        upwdFlag=/^[^\s]{6,18}$/;
        if(upwdFlag.test(this.value)){
            o_pwd.innerHTML="密码正确".fontcolor("green")
        }else {
            o_pwd.innerHTML="密码不正确";
        }
    }
    oForm.onsubmit=function () {
        if(unameFlag&&upwdFlag){
            var useInfo={
                name:this.uname.value,
                pwd:this.upwd.value
            };
            var userList=JSON.parse(getCookieByName('mi')||'[]')
            var flag=true;
            for (var i = 0; i < userList.length; i++) {
                if(userList[i].name==useInfo.name){
                    flag=false;
                    alert("该用户名已注册");
                    return false;
                }
            }
            if(flag){
                userList.push(useInfo);
                setCookie('mi',JSON.stringify(userList),10);
                confirm("注册成功,是否现在登录")?window.location="login.html":"";
            }
        }
        return false;
    }
</script>